// src/api/api.js
import axios from 'axios';

const API_URL = 'https://qianfan.baidubce.com/v2/app/conversation';
const ACCESS_KEY = 'ALTAKaU9zV1tH84u5elaoKfC0F';
const SECRET_KEY = '905f16fd276f43ab9de71c084ca564ac';
// 这里需要根据实际规则生成鉴权字符串，暂时使用示例中的格式
const AUTH_TOKEN = 'Bearer bce-v3/ALTAK-BYltaVjzMxDcwcjJJlj8X/2d5e363658b6f823527b0564954eb5cb9b0be60f';

export const getChatResponse = async (message) => {
    const headers = {
        'Content-Type': 'application/json',
        'X-Appbuilder-Authorization': AUTH_TOKEN
    };
    const data = {
        // 假设请求体需要包含 app_id 和消息内容
        "app_id": "7fa416a7-889a-4091-b935-5572015f2428",
        "messages": [
            {
                "role": "user",
                "content": message
            }
        ]
    };

    try {
        const response = await axios.post(API_URL, data, { headers });
        return response.data.result; // 假设返回结果在 result 字段中
    } catch (error) {
        console.error('请求聊天接口出错:', error);
        throw error;
    }
};